﻿@model Xuanren_FrontEnd.Model.Product

@{
    Layout = null;
    var list = ViewBag.Category as List<Xuanren_FrontEnd.Model.Category>;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Update</title>
    <link href="~/Content/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/lib/layui/layui.js"></script>
</head>
<body>
    <form id="fUpdate" class="layui-form" action="">
        <input type="hidden" name="id" id="id" value="@Model.id" />
        <div class="layui-form-item">
            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" value="@Model.name" required lay-verify="required" placeholder="请输入产品名称" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">产品品牌</label>
            <div class="layui-input-inline">
                <input type="text" name="brand" value="@Model.brand" required lay-verify="required" placeholder="请输入产品品牌" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品介绍</label>
            <div class="layui-input-inline">
                <input type="text" name="info" value="@Model.info" required lay-verify="required" placeholder="请输入产品介绍" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品规格</label>
            <div class="layui-input-inline">
                <input type="text" name="specification" value="@Model.specification" required lay-verify="required" placeholder="请输入产品规格" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品价格</label>
            <div class="layui-input-inline">
                <input type="text" name="price" value="@Model.price" required lay-verify="required" placeholder="请输入产品价格" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-inline">
                <input type="text" name="create_time" id="create_time" value="@Model.create_time" required lay-verify="date" placeholder="请选择创建时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产品默认图片</label>
            <div class="layui-input-block">
                <input type="file" id="my_file" name="file">
                <input type="text" name="image" id="image" hidden value="@Model.image" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <img id="my_img" src="/images/@Model.image" style="width:200px;height:200px" />
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">产品类型</label>
            <div class="layui-input-inline">
                <select id="category_id" name="category_id">
                    <option value="">---请选择产品类型---</option>
                    @foreach (var item in list)
                    {

                        if (Model.category_id == item.id)

                        {
                            <option value="@item.id" selected>@item.TypeName</option>
                        }
                        else
                        {
                            <option value="@item.id">@item.TypeName</option>
                        }

                    }

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>

        //Demo

        layui.use(['form', 'upload', 'laydate'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.$;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#create_time'
            });
            upload.render({
                elem: "#my_file",
                url: "/Back/Home/UploadImg",
                done: function (res) {
                    if (res.code == 0) {
                        $("#my_img").attr("src", "/images/" + res.path);
                        $("#image").val(res.path);
                    }
                }
            })


            //监听提交
            form.on('submit(formDemo)', function (data) {
                var fUpdate = $("#fUpdate").serialize();
                $.post("/Back/Product/Update", fUpdate, function (res) {
                    if (res.suc) {
                        layer.alert(res.msg);
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        window.parent.location.reload();
                    } else {
                        layer.alert(res.msg);
                    }
                }, "json")
                return false;
            });
        });
    </script>
</body>
</html>
